package world.xuewei.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import world.xuewei.dao.ShopActivityDao;
import world.xuewei.service.ShopActivityService;
import org.springframework.stereotype.Service;
import world.xuewei.model.entity.ShopActivity;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
* @author 陈相州
* @description 针对表【shop_activity】的数据库操作Service实现
* @createDate 2024-11-28 16:51:16
*/
@Service
public class ShopActivityServiceImpl implements ShopActivityService{

    @Autowired
    private ShopActivityDao shopActivityDao;

    @Override
    public List<ShopActivity> getAllShopActivity(Long userId) {
        return shopActivityDao.getAllShopActivity(userId);
    }

    @Override
    public List<ShopActivity> getShopActivityList(Long merchant_id) {
        // 获取当前商家对应的活动
        List<ShopActivity> shopActivityList = shopActivityDao.getShopActivityList(merchant_id);
        for (ShopActivity shopActivity : shopActivityList) {
            // 判断当前活动的结束时间是否小于或等于当前时间，小于的话代表已经到了活动结束时间或过了活动结束时间
            if (shopActivity.getEndTime() != null && shopActivity.getEndTime().getTime() <= new Date().getTime()) {
                // 修改活动状态
                shopActivityDao.setIsStatus(shopActivity.getId());
            }
        }
        return shopActivityDao.getShopActivityList(merchant_id);
    }

    // 添加
    @Override
    public int addShopActivity(ShopActivity shopActivity) {
        return shopActivityDao.addShopActivity(shopActivity);
    }

    // 修改
    @Override
    public int updateShopActivity(ShopActivity shopActivity) {
        return shopActivityDao.updateShopActivity(shopActivity);
    }

    // 删除
    @Override
    public int deleteShopActivity(Long id) {
        return shopActivityDao.deleteShopActivity(id);
    }
}




